﻿using System;
using System.Web;

namespace Dexter.Dependency.Autofac {
	public class AutofacContainerFactory : IDexterContainerFactory {
		#region IDexterContainerFactory Members

		public IDexterContainer Create ( ) {
			return Create ( null );
		}

		public IDexterInstaller CreateInstaller ( ) {
			return new AutofacInstaller ( );
		}

		public IDexterContainer Create ( string configuration ) {
			var container = new AutofacContainer();
			if (!String.IsNullOrEmpty ( configuration )) {
				configuration = HttpContext.Current != null
									? HttpContext.Current.Server.MapPath ( configuration )
									: string.Concat ( AppDomain.CurrentDomain.BaseDirectory, configuration.Replace ( "~/", string.Empty ) );
			}

			container.Configure ( configuration );

			return container;
		}

		#endregion
	}
}